cmake_minimum_required(VERSION 3.5)

project(ideaShareSDKDemo LANGUAGES CXX)

# 跨平台宏区分
if(WIN32)
set(CMAKE_PREFIX_PATH "D:\\Qt\\Qt5.14.2\\5.14.2\\msvc2017")                  
elseif(APPLE)
set(CMAKE_PREFIX_PATH "~/Qt5.12.8/5.12.8/clang_64")
endif(WIN32)

#set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(CMAKE_VERSION VERSION_LESS "3.7.0")
    set(CMAKE_INCLUDE_CURRENT_DIR ON)
endif()

# QtCreator supports the following variables for Android, which are identical to qmake Android variables.
# Check http://doc.qt.io/qt-5/deployment-android.html for more information.
# They need to be set before the find_package(Qt5 ...) call.

#if(ANDROID)
#    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
#    if (ANDROID_ABI STREQUAL "armeabi-v7a")
#        set(ANDROID_EXTRA_LIBS
#            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so
#            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so)
#    endif()
#endif()

find_package(Qt5 COMPONENTS Widgets Core Gui Network LinguistTools REQUIRED)

include_directories(
     ${PROJECT_SOURCE_DIR}/inc
     ${CMAKE_BINARY_DIR})
# 多语种
set(TS_FILES ${PROJECT_SOURCE_DIR}/res/IdeaShare_zh_CN.ts)

set(RC_FILES ${PROJECT_SOURCE_DIR}/res/IdeaShare.qrc)

# 源代码
#set(SOURCES
#    src/main.cpp
#    src/mainwindow.cpp)
FILE(GLOB SOURCES "${PROJECT_SOURCE_DIR}/src/*.cpp")

# 头文件
#set(HEADERS
#    inc/mainwindow.h)
FILE(GLOB HEADERS "${PROJECT_SOURCE_DIR}/inc/*.h")

# ui
#set(FORMS
#    form/mainwindow.ui)
FILE(GLOB FORMS "${PROJECT_SOURCE_DIR}/form/*.ui")

# 链接库的路径
link_directories(
    "${PROJECT_SOURCE_DIR}/lib"
    )

#通过Ui文件生成对应的头文件，一定要添加
qt5_wrap_ui(WRAP_FILES ${FORMS})

qt5_create_translation(QM_FILES
    ${PROJECT_SOURCE_DIR}/inc
    ${PROJECT_SOURCE_DIR}/src
    ${PROJECT_SOURCE_DIR}/form
    ${TS_FILES}
    OPTIONS -source-language en_US -no-obsolete)
# ---------------------------- 构建 --------------------------
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/libs)



# 编译可执行程序
if(WIN32)
  set(app_WINRC "${PROJECT_SOURCE_DIR}/res/IdeaShare.rc")
  set_property(SOURCE IdeaShare.rc APPEND  PROPERTY
    OBJECT_DEPENDS ${PROJECT_SOURCE_DIR}/res/images/app.ico
  )
add_executable(${PROJECT_NAME} WIN32 ${SOURCES} ${HEADERS} ${FORMS} ${RC_FILES} ${app_WINRC})
#add_executable(${PROJECT_NAME} WIN32 ${SOURCES} ${HEADERS} ${FORMS} ${QM_FILES} ${RC_FILES} ${app_WINRC})
else(APPLE)
  add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS} ${FORMS} ${QM_FILES} ${RC_FILES})
endif(WIN32)

add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:Qt5::Widgets> $<TARGET_FILE_DIR:${PROJECT_NAME}>
    COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:Qt5::Core> $<TARGET_FILE_DIR:${PROJECT_NAME}>
    COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:Qt5::Gui> $<TARGET_FILE_DIR:${PROJECT_NAME}>
    )
# tup开头的链接库
file(GLOB LIBS "${PROJECT_SOURCE_DIR}/lib/tup*")

# 链接依赖的动态库 
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Widgets Qt5::Core Qt5::Gui ${LIBS}  ideashare_data_projection_client ideashare_wrapper securec  QtSingleApp)

target_include_directories(${PROJECT_NAME}
    PRIVATE
    "${PROJECT_SOURCE_DIR}/include"
    "${PROJECT_SOURCE_DIR}/inc"
     ${CMAKE_BINARY_DIR}
)

if(MSVC_VERSION)
   set_target_properties(${PROJECT_NAME} PROPERTIES
	#LINK_FLAGS "/MANIFEST /NOLOGO /MANIFESTUAC:level='highestAvailable'"
    COMPILE_FLAGS "-DSERVICES_IMPORT -DQT_MESSAGELOGCONTEXT"
 )
endif(MSVC_VERSION)

# ---------------------------- 集成 --------------------------
# 完成文件拷贝
FILE(GLOB DLLS
    "${PROJECT_SOURCE_DIR}/dll/*.dll"
    "${PROJECT_SOURCE_DIR}/dll/*.pdb"
    )

FILE(COPY ${DLLS} DESTINATION ${PROJECT_BINARY_DIR}/bin)
# 完成FAULT REPORT拷贝
FILE(GLOB FAULT_REPORT
    "${PROJECT_SOURCE_DIR}/faultReport/*.ini"
    "${PROJECT_SOURCE_DIR}/faultReport/FaultReport.exe"
	"${PROJECT_SOURCE_DIR}/faultReport/*.dll"
    )
FILE(COPY ${FAULT_REPORT} DESTINATION ${PROJECT_BINARY_DIR}/bin)
